package com.chuanyang.driverh.mainmy.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseListAdapter;
import com.chuanyang.driverh.responseresult.LinesManageData;

import java.util.ArrayList;


public class LinesManageAdapter extends BaseListAdapter<LinesManageData.DataBean> {

    private ArrayList<LinesManageData.DataBean> linesList;
    private Context context;
    private ViewHolder holder;

    public LinesManageAdapter(Context context, ArrayList<LinesManageData.DataBean> linesList) {
        super(context, linesList);
        this.context = context;
        this.linesList = linesList;
        //此处不传入集合，则默认集合长度为0，在setdataresult（）方法中，添加数据并刷新
    }

    @Override
    public View getZkView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.my_item_linesmanage, null);
            holder = new ViewHolder();
            holder.iv_lines_delete = (ImageView) convertView.findViewById(R.id.iv_lines_delete);
            // holder.iv_lines_startcity= (ImageView) convertView.findViewById(R.id.iv_lines_startcity);
            // holder.iv_lines_endcity= (ImageView) convertView.findViewById(R.id.iv_lines_endcity);
            holder.tv_path_manage_start_city = (TextView) convertView.findViewById(R.id.tv_path_manage_start_city);
            holder.tv_path_manage_end_city = (TextView) convertView.findViewById(R.id.tv_path_manage_end_city);
            holder.tv_path_manage_start_city = (TextView) convertView.findViewById(R.id.tv_path_manage_start_city);
            holder.tv_lines_startcity = (TextView) convertView.findViewById(R.id.tv_lines_startcity);
            holder.tv_lines_endcity = (TextView) convertView.findViewById(R.id.tv_lines_endcity);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        LinesManageData.DataBean bean = getItem(position);
        holder.tv_path_manage_start_city.setText(bean.getStartCity());
        holder.tv_lines_startcity.setText(bean.getStartAddr());
        holder.tv_path_manage_end_city.setText(bean.getTargetCity());
        holder.tv_lines_endcity.setText(bean.getTargetAddr());
        holder.iv_lines_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null)
                {
                     listener.onCustomerListener( holder.iv_lines_delete,position);
                }
//                LinesManageAdapter.this.remove(position);
           }
        });
        return convertView;
    }

    private class ViewHolder {
        ImageView iv_lines_endcity;
        ImageView iv_lines_startcity;
        ImageView iv_lines_delete;
        TextView tv_path_manage_start_city;//起点城市
        TextView tv_path_manage_end_city;
        TextView tv_lines_startcity;//详细起点
        TextView tv_lines_endcity;
    }

}
